package com.chmingx.JavaBasic.rabbitmq.work;


import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws Exception {
        try (Channel channel = RabbitMQUtils.getChannel()) {
            channel.queueDeclare("work", false, false, false, null);
            // 从控制台当中接收信息
            Scanner scanner = new Scanner(System.in);
            while (scanner.hasNext()) {
                String message = scanner.next();
                channel.basicPublish("", "work", null, message.getBytes(StandardCharsets.UTF_8));
                System.out.println("发送消息完成:" + message);
            }
        }
    }
}
